<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');
class Address extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->verify_user();
	}

	public function index()
	{
		$this->view('address');
	}

	public function data()
	{
		$page = ($this->input->post('page') ? intval($this->input->post('page')) : 1);
		$rows = ($this->input->post('rows') ? intval($this->input->post('rows')) : 10);
		$id = intval($this->input->post('id'));
		$username = $this->input->post('username');

		if ($id) {
			$this->db->where('id', $id);
		}

		if ($username) {
			$user = $this->db->where('username', $username)->get('user')->row_array();
			$this->db->where_in('user_id', $user['id']);
		}

		$result['total'] = $this->db->count_all_results('address');
		$start = ($page - 1) * $rows;
		$list = $this->db->limit($rows, $start)->get('address')->result_array();

		foreach ($list as $k => $v) {
			$list[$k]['add_time'] = date('Y-m-d H:i', $v['add_time']);
			$user = $this->db->where('id', $v['user_id'])->get('user')->row_array();
			$list[$k]['username'] = $user['username'];
			$coin = $this->db->where('id', $v['coin_id'])->get('coin')->row_array();
			$list[$k]['coin'] = $coin['cn_name'];
		}

		$result['rows'] = $list;
		echo json_encode($result);
	}
}

?>
